<?php

/**
 * Description of Actor
 *
 * @author Luc
 */
class Application_Model_Actor extends Zend_Db_Table_Abstract {

    protected $_name = 'Actor';

    public function getActor($id) {
        $sql = "SELECT Actor_ID, Name FROM Actor WHERE Actor_ID = ?";
        $params = array($id);
        return $this->getAdapter()->query($sql, $params)->fetchAll();
    }
    
    public function getActor2($id) {
        $sql = "SELECT * FROM Actor WHERE Actor_ID = ?";
        $params = array($id);
        $values =  $this->getAdapter()->query($sql, $params)->fetchAll();
        return $values[0];
    }

    public function getActors() {
        $sql = "SELECT Name, Actor_ID FROM Actor";
        return $this->getAdapter()->query($sql)->fetchAll();
        
    }
    
    public function getActors2() {
        $sql = "SELECT * FROM Actor";
        return $this->getAdapter()->query($sql)->fetchAll();
        
    }
    
    public function search($string) {
        $sql = "SELECT Actor_ID, Name FROM Actor WHERE Name LIKE ? LIMIT 0,7";
        $params = array("%" . $string . "%");
        return $this->getAdapter()->query($sql, $params)->fetchAll();
    }
    
    /**
     * This function stores a new actor in the database
     * 
     * @param Name The actors name
     * @param Birthday The actors' birthday (mm-dd-yy)
     * @param Picture A picture of the actor
     */
    public function addActor($Name, $Birthday, $Picture) {
		$sql  = "INSERT INTO Actor (Actor_ID, Name, Birthday, Picture) VALUES (NULL, :name, :birthday, :picture)";
		$params = array(":name" => $Name, ":birthday" => $Birthday, ":picture" => $Picture);
		$this->getAdapter()->query($sql, $params);
	}
	
	public function updateActor($Actor_ID, $Name, $Birthday, $Picture){
		$sql = "UPDATE Actor a Set a.Name = :name, a.Birthday = :bday, a.Picture = :pic WHERE a.Actor_ID = :id";
		$params = array(":name" => $Name, ":bday" => $Birthday, ":pic" => $Picture, ":id" => $Actor_ID);
		$this->getAdapter()->query($sql, $params);
	}
	
	public function deleteActor($id) {
		$sql = "DELETE FROM Actor WHERE Actor_ID = ?";
		$params = array($id);
		$this->getAdapter()->query($sql, $params);
	}
}

?>
